package com.yan.utils;

import java.io.IOException;
import java.util.Date;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import com.yan.bean.Link;
import com.yan.comm.DateUtil;
import com.yan.mapper.LinkMapper;
import com.yan.service.RedisService;
import com.yan.service.TryableService;

@SpringBootApplication
@ComponentScan(basePackages = { "com.yan.controller", "com.yan.config", "com.yan.service", "com.yan.requestLimit" })
public class Application implements EmbeddedServletContainerCustomizer {

	@Override
	public void customize(ConfigurableEmbeddedServletContainer config) {
		// TODO Auto-generated method stub
		config.setPort(8899);
	}

	public static void main(String[] args) {
		ConfigurableApplicationContext appContext = SpringApplication.run(Application.class, args);

		LinkMapper linkMapper = appContext.getBean("linkMapper", LinkMapper.class);

		Link link = linkMapper.find();

		System.out.println(link);

		RedisService redisService = appContext.getBean("redisService", RedisService.class);
		// String
		redisService.set("redisKey", "yan");
		String redisValue = (String) redisService.get("redisKey");
		System.out.println(redisValue);

		// // Set
		redisService.add("setAdd", "liang");
		System.out.println(redisService.setMembers("setAdd"));

		// // Hash Map
		redisService.hmSet("hash", "hashKey", "hashValue");
		System.out.println(redisService.hmGet("hash", "hashKey"));

		redisService.lPush("lpList", "lp");
		System.out.println(redisService.lRange("lpList", 0, 1));

		TryableService tryable = (TryableService) appContext.getBean("tryableService", TryableService.class);
		try {
			tryable.call();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			redisService.setBit("20170-09-01", 10001L, true);
			redisService.setBit("20170-09-01", 10002L, true);
			redisService.setBit("20170-09-01", 10003L, true);
			redisService.setBit("20170-09-04", 10001L, true);
			redisService.setBit("20170-09-05", 10001L, true);
			System.out.println("统计数字=" + redisService.getBit("20170-09-01"));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		System.out.println(tryable.getCurrentDate());
	}

}
